package com.xmim.fulcrum.handler.impl;

import com.xmim.core.cocurrent.FutureTaskScheduler;
import com.xmim.core.constants.MessageCode;
import com.xmim.core.entity.Message;
import com.xmim.core.entity.Request;
import com.xmim.core.session.Session;
import com.xmim.core.session.user.UserSession;
import com.xmim.fulcrum.FulcrumDiscover;
import com.xmim.fulcrum.handler.RequestMessageHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RequestHandler extends RequestMessageHandler {

    public RequestHandler(FulcrumDiscover fulcrumDiscover) {
        super(fulcrumDiscover);
    }

    @Override
    public void handler0(UserSession userSession, Message<Request> msg) {
        if (MessageCode.MSG_REQUEST != msg.getType()) {
            return;
        }
        Request request = msg.getBody();
        String sessionId = request.getSessionId();
        //异步处理转发的逻辑
        FutureTaskScheduler.add(() ->
        {
            Session session = fulcrumDiscover.getSession(sessionId);
            session.writeAndFlush(request);
        });
    }
}
